package com.ppgames.gm.gmsystem;

/**
 * GM上下文
 *
 * @author Joeg
 * @email 840459673@qq.com
 * @date 2018/4/19
 */
public class GmContext {

    private String id;
    private String requestUri;
    private String sourceIP;
    private String token;

    private static ThreadLocal<GmContext> context = new ThreadLocal<>();


    public static GmContext getContext() {
        GmContext cxt = context.get();
        if (cxt == null) {
            cxt = new GmContext();
            cxt.id = GmCore.Util.createUUID();
            cxt.requestUri = "";
            cxt.token = "";
            setContext(cxt);
        }
        return cxt;
    }

    public static void setContext(GmContext _context) {
        if (_context.token == null) {
            _context.token = "";
        }
        context.set(_context);
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRequestUri() {
        return requestUri;
    }

    public void setRequestUri(String requestUri) {
        this.requestUri = requestUri;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getSourceIP() {
        return sourceIP;
    }

    public void setSourceIP(String sourceIP) {
        this.sourceIP = sourceIP;
    }
}
